package com.group10.mapper;

import com.group10.entity.User;
import com.group10.entity.UserState;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public interface UserMapper {

    @Select("select user.*, user_state.state,user_state.time from user join user_state on user.id = user_state.id where user.id=#{id} ")
    User findById(String id);

    @Update("update user_state set state=0,time=null where id=#{id} ")
    int updateState(String id);

    @Update("update user_state set state=1,time=#{time} where id=#{id}")
    int silence(String id,String time);

    @Update("update user_state set state=2,time=#{time} where id=#{id}")
    int suspend(String id,String time);

    @Select("select count(*) from user where id=#{id}")
    int findUser(String id);

    @Select("select * from user_state where id=#{id}")
    UserState getState(String id);

    @Insert("insert into user values(#{id},#{password},#{email},#{name},#{sex},#{age},#{ethnic},#{img})")
    int insertUser(String id,String password,String email,String name,String sex,int age,String ethnic,String img);

    @Insert("insert into user_state values(#{id},0,null)")
    void insertUserState(String id);

    @Update("update user set password=#{newPsd} where email=#{email}")
    int findPassword(String email,String newPsd);

    @Select("select user.*, user_state.state,user_state.time from user join user_state on user.id = user_state.id ")
    ArrayList<User> getAllUser();

    @Select("select * from user_state")
    ArrayList<UserState> getAllUserState();

//    @Update("update user set email=#{email} where id=#{id}")
//    int updateEmail(String id,String email);

    @Update("update user set name=#{name},email=#{email},age=#{age},ethnic=#{ethnic} where id=#{id}")
    int updateUser(User user);

    @Update("update user set img=#{img} where id=#{id}")
    int updateImg(String id,String img);
}
